<template>
  <div>
    <el-upload :show-file-list="false" accept=".svg" :before-upload="handleUpload">
      <el-button type="primary" size="small">上传自定义 SVG 图标</el-button>
    </el-upload>

    <el-input
      v-model="svgCode"
      type="textarea"
      placeholder="或直接粘贴 SVG 代码"
      rows="6"
      style="margin-top: 10px"
    />

    <el-button type="success" size="small" @click="importSvg">导入图形</el-button>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const emit = defineEmits(['import-svg'])

const svgCode = ref('')

function handleUpload(file) {
  const reader = new FileReader()
  reader.onload = () => {
    svgCode.value = reader.result
  }
  reader.readAsText(file)
  return false // 阻止自动上传
}

function importSvg() {
  if (!svgCode.value.trim()) return

  emit('import-svg', svgCode.value)
}
</script>
